#include <my_global.h>
#include <mysql.h>

#define _MYSQL(conn,func)   \
    do {    \
    if ((func)) {   \
	printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));	\
	exit(1); }  \
    }while(0)

int main(int argc, char **argv)
{

  MYSQL *conn;

  conn = mysql_init(NULL);
  _MYSQL(conn, conn == NULL);
  _MYSQL(conn, mysql_real_connect(conn, "localhost", "root", "root123", "testdb", 0, NULL, 0) == NULL);
  _MYSQL(conn, mysql_query(conn, "CREATE TABLE writers(name VARCHAR(25), age tinyint default 0)"));

  _MYSQL(conn, mysql_query(conn, "INSERT INTO writers VALUES('Leo Tolstoy',25)"));
  _MYSQL(conn, mysql_query(conn, "INSERT INTO writers VALUES('Jack London',31)"));
  _MYSQL(conn, mysql_query(conn, "INSERT INTO writers VALUES('Honore de Balzac',34)"));
  _MYSQL(conn, mysql_query(conn, "INSERT INTO writers VALUES('Lion Feuchtwanger',55)"));
  _MYSQL(conn, mysql_query(conn, "INSERT INTO writers VALUES('Emile Zola',76)"));

  mysql_close(conn);

}

